package org.zcl.sqlserver.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

/**
 * .
 *
 * @author zhuchenglin
 * @since 2024/10/25 10:53
 */
@Slf4j
public class JsonUtils {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static String toJson(Object object) {
        try {
            return objectMapper.writeValueAsString(object);
        } catch (Exception e) {
            log.error("json writeValueAsString 异常", e);
            return null;
        }
    }

    public static <T> T readValue(String jsonMessage, Class<T> valueType) {
        try {
            return objectMapper.readValue(jsonMessage, valueType);
        } catch (Exception e) {
            log.error("json readValue 异常", e);
            return null;
        }
    }

}
